#include "head_s.h"

int create_dir(const user_t* status, const portocol_t* portocol, int net_fd) {
    printf("The cmd: mkder\n");
    

    char the_path[1024] = {0};
    strcpy(the_path, status->base_path);
    strcat(the_path, status->user_name);
    strcat(the_path, status->path);
    printf("status_path : %s\n", status->path);
    printf("The path : %s\n", the_path);

    DIR *dir = opendir(the_path);
    struct dirent* curr;
    while((curr = readdir(dir)) != NULL) {
        if(curr->d_type == DT_DIR) {
            if(strcmp(curr->d_name, status->arg) == 0) {
                send(net_fd, "failed", 6, MSG_NOSIGNAL);
                return 0;
            }
        }
    }
    int size = strlen(the_path);
    if(the_path[size-1] != '/') {
        the_path[size] = '/';
        the_path[size+1] = '\0';
    }
    strcat(the_path, status->arg);
    printf("The dir path: %s\n", the_path);

    mkdir(the_path, 0777);

    
    send(net_fd, "succeeded", 9, 0);
    closedir(dir);

    return 0;
}
